﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using iHub.App_Code;

namespace iHub
{
    public partial class modifyAccountNameb : Form
    {
        private string name = "";
        public modifyAccountNameb(string n)
        {
            InitializeComponent();
            name = n;
            this.FormClosing += new FormClosingEventHandler(Form_Closing);
        }

        private void Form_Closing(object sender, FormClosingEventArgs e)
        {
            if (e.CloseReason == CloseReason.UserClosing)
            {
                Form2.form.Enabled = true;
            }
        }

        private void modifyname_Click(object sender, EventArgs e)
        {
            string newname = accountnameb.Text;
            StringValidator validator = new StringValidator();

            try
            {
                if (newname != "")
                {
                    if (validator.IsSafeString(newname))
                    {
                        if (Form2.form.checkmodifiedname(newname))
                        {
                            Form2.form.editAccountName(newname, name);
                            MessageBox.Show("Name successfully modified", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            Form2.form.Enabled = true;
                            this.Dispose();
                        }
                        else
                        {
                            MessageBox.Show("Name already exists", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                        }
                    }
                    else
                    {
                        MessageBox.Show("There are illegal characters present in the text", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    }
                }
                else
                {
                    MessageBox.Show("No value entered", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.ToString(), "Fatal", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }

    }
}
